#pragma once

// DevIL
#include <il.h>
#include <ilu.h>
#include <ilut.h>
//#include <devil_internal_exports.h>
#pragma comment(lib, "DevIL.lib")
#pragma comment(lib, "ILU.lib")
#pragma comment(lib, "ILUT.lib")


#include "Globals.hpp"
#include "OpenGL.hpp"
#include "SuperData.h"
#include <vector>
#include <map>
#include <string>
using namespace std;

#define ImageManager ImageLoader::Instance()

class ImageLoader
{
public:

	struct Image
	{
		GLuint texture;
		Dimension padded, orig;
		string name;
	};

	struct MinimapData
	{
		int imageID;
		float r, g, b;
	};

	struct SubBase
	{
		string AnimationType;
		vector<int> FrameIDs;
		float UpdateTime;
		int TotalFrames;
	};

	void Init();	// Run the Lua script that creates all of the ImageLoader's IDs

	static int LoadGraphic(string imageName, string filename);
	
	// Animation
	void AnimCreate(string baseName);
	void AnimAdd(string baseName, string subBaseName, string imageName);
	void AnimChange(string baseName, string subBaseName, string member, int newData); // base name, subbase name, the member of the sub base, the new data
	vector<SubBase> GetAnimation(string baseName);
	SubBase GetSubBase(string baseName, string subBaseName);

//	Image* GetImageData(unsigned int imageID) {assert((mImages.size() - 1 > imageID) && "Attempted to GetImageData for an invalid imageID"); return &(mImages[imageID]);}
	unsigned int GetTotalImages() {return mImages.size();}
	vector<Image> GetAllImages() {return mImages;}

	// Minimap
	void AddMinimapKey(string imageName, float r, float g, float b);
	MinimapData* GetMinimapData(int imageID) {return &(mMinimapData[imageID]);}


	int GetImageID(const string& imageID) {return mImageNameToID[imageID];}

	static void DeleteAllTextures();
	static void DeleteAllAnimations();
	
	
	static ImageLoader* Instance();

private:
	//ImageLoader(){}
	//ImageLoader(const ImageLoader&);
	//ImageLoader& operator =(const ImageLoader&);
	//~ImageLoader() {}

	static vector<Image>					mImages;
	static map<int, MinimapData>			mMinimapData;
	static map<string, int>					mImageNameToID;
	static vector<string>					mUsedPaths;
	static map<string, vector<SubBase> >	mAnimationBases;

	static void DeleteTexture(int imgID);
		

};